package com.hckjsec.cloud.controller;

import java.util.List;

import com.hckjsec.common.utils.SecurityUtils;
import com.hckjsec.common.utils.StringUtils;
import com.hckjsec.common.utils.sign.Base64Converter;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.hckjsec.common.annotation.Log;
import com.hckjsec.common.core.controller.BaseController;
import com.hckjsec.common.core.domain.AjaxResult;
import com.hckjsec.common.enums.BusinessType;
import com.hckjsec.cloud.domain.AppletsPublicNotify;
import com.hckjsec.cloud.service.IAppletsPublicNotifyService;
import com.hckjsec.common.utils.poi.ExcelUtil;
import com.hckjsec.common.core.page.TableDataInfo;

/**
 * 通知公告Controller
 * 
 * @author cyt
 * @date 2021-09-04
 */
@RestController
@RequestMapping("/system/notify")
public class AppletsPublicNotifyController extends BaseController
{
    @Autowired
    private IAppletsPublicNotifyService appletsPublicNotifyService;

    /**
     * 查询通知公告列表
     */
    @GetMapping("/list")
    public TableDataInfo list(AppletsPublicNotify appletsPublicNotify)
    {
        startPage();
        appletsPublicNotify.setDeptId(SecurityUtils.getDeptId());
        List<AppletsPublicNotify> list = appletsPublicNotifyService.selectAppletsPublicNotifyList(appletsPublicNotify);
        return getDataTable(list);
    }

    /**
     * 导出通知公告列表
     */
    @Log(title = "通知公告", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(AppletsPublicNotify appletsPublicNotify)
    {
        appletsPublicNotify.setDeptId(SecurityUtils.getDeptId());
        List<AppletsPublicNotify> list = appletsPublicNotifyService.selectAppletsPublicNotifyList(appletsPublicNotify);
        ExcelUtil<AppletsPublicNotify> util = new ExcelUtil<AppletsPublicNotify>(AppletsPublicNotify.class);
        return util.exportExcel(list, "notify");
    }

    /**
     * 获取通知公告详细信息
     */
    @GetMapping(value = "/{notifyId}")
    public AjaxResult getInfo(@PathVariable("notifyId") Long notifyId)
    {
        return AjaxResult.success(appletsPublicNotifyService.selectAppletsPublicNotifyById(notifyId));
    }

    /**
     * 新增通知公告
     */
    @Log(title = "通知公告", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AppletsPublicNotify appletsPublicNotify)
    {
        appletsPublicNotify.setDeptId(SecurityUtils.getDeptId());
        appletsPublicNotify.setOperator(SecurityUtils.getUserId());
        if (!"".equals(StringUtils.isHcNull(appletsPublicNotify.getContent(),""))){//解密
            appletsPublicNotify.setContent(Base64Converter.decode(appletsPublicNotify.getContent()));
        }else{
            appletsPublicNotify.setContent(appletsPublicNotify.getContent());
        }
        return toAjax(appletsPublicNotifyService.insertAppletsPublicNotify(appletsPublicNotify));
    }

    /**
     * 修改通知公告
     */
    @Log(title = "通知公告", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AppletsPublicNotify appletsPublicNotify)
    {
        if (!"".equals(StringUtils.isHcNull(appletsPublicNotify.getContent(),""))){//解密
            appletsPublicNotify.setContent(Base64Converter.decode(appletsPublicNotify.getContent()));
        }else{
            appletsPublicNotify.setContent(appletsPublicNotify.getContent());
        }
        return toAjax(appletsPublicNotifyService.updateAppletsPublicNotify(appletsPublicNotify));
    }

    /**
     * 删除通知公告
     */
    @Log(title = "通知公告", businessType = BusinessType.DELETE)
	@DeleteMapping("/{notifyIds}")
    public AjaxResult remove(@PathVariable Long[] notifyIds)
    {
        return toAjax(appletsPublicNotifyService.deleteAppletsPublicNotifyByIds(notifyIds));
    }
}
